package com.jmoney.luckeylink.controller;

import static io.restassured.RestAssured.given;

import io.restassured.RestAssured;
import io.restassured.config.SSLConfig;
import io.restassured.response.Response;

public class LekeW_AuthorizeKey_Controller {
    /**
	    * 指定接口地址，获取住户授权的信息
	    * @param ApiUrl
	    * @return RoomUserMap
	    */
    public static Object[] GetRoomUserMap(String ApiUrl) throws Exception{

	       Response response = given()
	               .config((RestAssured.config().sslConfig(new SSLConfig().relaxedHTTPSValidation())))
	               .contentType("application/json")
	               .log().all()
	               .request()
	               .when()
	               .get(ApiUrl);

	       response.print();
           String Json = response.asString();
	       
	       int status_code = response.jsonPath().getInt("status_code");
	       String message = response.jsonPath().get("message");
	       
	       int user_id = response.jsonPath().getInt("data[0].data[0].id");
	       int community_unit_room_id = response.jsonPath().getInt("data[0].data[0].community_unit_room_id");
	       int user_community_id = response.jsonPath().getInt("data[0].data[0].user_community_id");

           Object[] RoomUserMap ={Json,status_code,message,user_id,community_unit_room_id,user_community_id};
           
	       return RoomUserMap;
	}   
    
    /**
	    * 指定接口地址，获取住户授权的成功信息
	    * @param ApiUrl
	    * @return AuthorizeInfo
	    */
    public static Object[] GetAuthorizeKeyInfo(String ApiUrl, String Param) throws Exception{

    	Response response = given()
	               .config((RestAssured.config().sslConfig(new SSLConfig().relaxedHTTPSValidation())))
	               .contentType("application/x-www-form-urlencoded; charset=UTF-8")
	               .log().all()
	               .request()
	               .body(Param)
	               .when()
	               .post(ApiUrl);

	       response.print();
           String Json = response.asString();
	       
	       int status_code = response.jsonPath().getInt("status_code");
	       String message = response.jsonPath().get("message");

           Object[] AuthorizeKeyInfo ={Json,status_code,message};
           
	       return AuthorizeKeyInfo;
	}     
}
